﻿@model AdvancedSettingsViewModel

@{
    Layout = "_LayoutAdmin";
}
@Html.AntiForgeryToken()

@section scripts{
    <script>
        $(function () {
            $(".btn-restart").click(function () {
                tryRestartWebsite();
            });

            $(".btn-reset").click(function () {
                tryResetWebsite();
            });
        });
    </script>
}

<partial name="_SettingsHeader" />

<form id="form-settings" asp-controller="Settings" asp-action="AdvancedSettings"
      data-ajax-begin="onUpdateSettingsBegin"
      data-ajax-complete="onUpdateSettingsComplete"
      data-ajax-failure="onUpdateSettingsFailed"
      data-ajax-success="onUpdateSettingsSuccess"
      data-ajax="true"
      data-ajax-method="POST">
    <div asp-validation-summary="All" class="text-danger"></div>
    <div class="row">
        <div class="col-md-6">
            <div class="card mb-4">
                <div class="card-header">Advanced Settings</div>
                <ul class="list-group list-group-flush">
                    <li class="list-group-item">
                        <label asp-for="EnablePingBackSend" class="control-label"></label>
                        <div class="material-switch float-right">
                            <input @(Model.EnablePingBackSend ? "checked=\"checked\"" : "") id="EnablePingBackSend" name="EnablePingBackSend" type="checkbox" value="true">
                            <label for="EnablePingBackSend" class="label-success"></label>
                            <input name="EnablePingBackSend" type="hidden" value="false">
                        </div>
                    </li>
                    <li class="list-group-item">
                        <label asp-for="EnablePingBackReceive" class="control-label"></label>
                        <div class="material-switch float-right">
                            <input @(Model.EnablePingBackReceive ? "checked=\"checked\"" : "") id="EnablePingBackReceive" name="EnablePingBackReceive" type="checkbox" value="true">
                            <label for="EnablePingBackReceive" class="label-success"></label>
                            <input name="EnablePingBackReceive" type="hidden" value="false">
                        </div>
                    </li>
                </ul>
                <div class="card-body">
                    <div class="form-group">
                        <label asp-for="DNSPrefetchEndpoint" class="control-label"></label>
                        <input asp-for="DNSPrefetchEndpoint" class="form-control" />
                        <span asp-validation-for="DNSPrefetchEndpoint" class="text-danger"></span>
                    </div>
                    <div class="form-group">
                        <label asp-for="RobotsTxtContent" class="control-label"></label>
                        <textarea asp-for="RobotsTxtContent" class="form-control textarea-code" cols="60" rows="10"></textarea>
                        <span asp-validation-for="RobotsTxtContent" class="text-danger"></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card">
                <div class="card-header">
                    Options
                </div>
                <div class="card-body">
                    <h6>Restart Website</h6>
                    <hr />

                    <div class="alert alert-warning">Try to shutdown and restart the website, this will terminate all current requests.</div>

                    <button class="btn btn-danger" data-toggle="modal" data-target="#restartModal">Restart</button>

                    <h6 class="mt-4">System Reset</h6>
                    <hr />

                    <div class="alert alert-warning">Erase all data and configuration.</div>

                    <button class="btn btn-danger" data-toggle="modal" data-target="#resetModal">Reset</button>
                </div>
            </div>
        </div>
    </div>
    <hr />
    <div class="form-group">
        <input id="btn-save-settings" type="submit" value="Save" class="btn btn-success" />
    </div>
</form>

<div class="modal fade" id="restartModal" tabindex="-1" role="dialog" aria-labelledby="restartModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="restartModalLabel">Restart Website</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                Are you sure to restart website? All current requests will be terminated.
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-danger btn-restart">Restart</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="resetModal" tabindex="-1" role="dialog" aria-labelledby="resetModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="resetModalLabel">System Reset</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                Are you ABSOLUTELY sure? ALL data and configuration will be erased!
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-danger btn-reset">Reset</button>
            </div>
        </div>
    </div>
</div>
